#include <string_view>

#include "ExtendDeviceManager.h"
#include "GuiContext.h"
#include "CodeScanner.h"
#include "PowerMonitor.h"
#include "DoorAlertor.h"
#include "AcSwitchDetector.h"
#include "ConfigManager.h"
#include "CurrentVoltageManager.h"


ExtendDeviceManager::ExtendDeviceManager() : IExtendDeviceManager(mouterCommunicator){
//    mouterCommunicator.setPort(StringUtility::EMPTY_STRING);
}

ExtendDeviceManager::~ExtendDeviceManager() {
    //dtor
}


bool ExtendDeviceManager::updateOnlineDevice(ChannelDevices& channelDevices) {
    DummyChannel& channel = *channelDevices.first;

    std::forward_list<ExtendDevicePtr>& deviceList =  channelDevices.second;
    bool allDeviceOnline = true;
    bool deviceOnline;
    //  std::forward_list<ExtendDevicePtr>::iterator iterator =deviceList.begin();

    if (deviceList.empty()) {
        allDeviceOnline = false;
    } else {
        deviceList.remove_if([&allDeviceOnline, &deviceOnline, &channel](ExtendDevicePtr& pExtendDevicePtr) {
            deviceOnline = pExtendDevicePtr->recheck();
            LOG_DEDUG("%s,recheck:%d", channel.mexceptionTip.c_str(), deviceOnline);
//        if (deviceOnline){
//            ++allDeviceOnline;
//        }
            allDeviceOnline &= deviceOnline;
            return !deviceOnline;

        });

    }

    return allDeviceOnline;
}



